﻿@model DefeatEpidemic.Models.Family

<div class="layui-row">
    <span class="layui-breadcrumb">
        <a href="~/home/index">首页</a>
        <a href="~/families/Index">家庭管理</a>
        <a>
            <cite>编辑家庭</cite>
        </a>
    </span>
    <a class="layui-btn layui-btn-xs" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon layui-icon-refresh-1" style="line-height:25px;font-size: 10px"></i>
    </a>
</div>
<hr />
<div class="layui-row">
    <form asp-action="Edit">
        <div asp-validation-summary="ModelOnly" class="text-danger"></div>
        <input type="hidden" asp-for="id" />
        <div class="layui-form-item">
            <label asp-for="name" class="layui-form-label"></label>
            <div class="layui-input-block">
                <input asp-for="name" class="layui-input" placeholder="请输入家庭姓名" lay-verify="required" />
            </div>
            <span asp-validation-for="name" class="text-danger"></span>
        </div>
        <div class="layui-form-item">
            <label asp-for="address" class="layui-form-label"></label>
            <div class="layui-input-block">
                <input asp-for="address" class="layui-input" placeholder="请输入地址" lay-verify="required" />
            </div>
            <span asp-validation-for="address" class="text-danger"></span>
        </div>
        <div class="layui-form-item">
            <input type="submit" value="保存" class="layui-btn" />
            <a asp-action="Index" class="layui-btn layui-btn-primary">返回列表</a>
        </div>
    </form>
    <hr />
    <div class="layui-form-item">
        <a class="layui-btn" href="javascript:;" id="btn_add">添加成员</a>
    </div>
    <table class="layui-table" id="table"></table>
</div>

<script type="text/html" class="layer_notice" style="display:none" id="div_add_member">
    <br />

    <div class="layui-row">
        <div class="layui-form-item">
            <label class="layui-form-label">检索</label>
            <div class="layui-input-inline">
                <input type="text" id="keyword" class="layui-input" placeholder="请输入人员姓名或身份证号" />
            </div>
            <a href="javascript:;" id="btn_search" class="layui-btn layui-btn-normal">检索</a>
            <a href="javascript:;" id="btn_add_save" class="layui-btn">确认添加</a>
        </div>
        <div class="layui-form-item">
            <table class="table" id="table2"></table>
        </div>

    </div>

</script>
<script type="text/html" id="checkboxTpl">
    <input type="checkbox" name="id" lay-skin="primary" lay-filter="ck_item" id="{{ d.id }}" class="ck">
</script>
<script type="text/javascript">
    var token = $('@Html.AntiForgeryToken()').val();
    var family_id = $("#id").val();
    var params = {
        url: '@Url.Action("GetFamilyMembers")',
        elem: '#table',
        where: { 'family_id': family_id },
        size: 'lg',
        page: true,
        cols: [ //表头
            //, { field: 'id', title: 'ID', sort: true, fixed: 'left' }
            { field: 'name', title: '姓名' }
            , { field: 'idcard', title: '身份证号' }
            , { field: 'mobile', title: '联系方式' }
            , { field: 'address', title: '地址' }
            , { field: 'companyName', title: '单位名称' }
            , { field: 'companyPlace', title: '上班地点' }
            , { field: 'remark', title: '备注' }
        ],
        height:630
    }
    getTable(params);

    $("#btn_add").click(function () {
        openDiv('选择人员', 'div_add_member', '70%', '80%',true);
        params.url = '@Url.Action("GetMembersNoFamily")';
        params.elem = '#table2';
        params.where = '';
        params.height = 550;
        params.cols = [
            { title: '<input type="checkbox" title="" lay-skin="primary" id="check_all" lay-filter="check_all" > 选择', templet: '#checkboxTpl', fixed: 'center', width: 100 }
            , { field: 'name', title: '姓名' }
            , { field: 'idcard', title: '身份证号' }
            , { field: 'mobile', title: '联系方式' }
            , { field: 'address', title: '地址' }
            , { field: 'companyName', title: '单位名称' }
            , { field: 'companyPlace', title: '上班地点' }
            , { field: 'remark', title: '备注' }
        ]
        getTable(params);
        //提交关联文档
        $("#btn_add_save").click(function () {
            console.log(1);
            var check = $("table input[type=checkbox]:checked");
            if (check.length > 0) {
                var checks = [];
                var has_checks = [];
                for (var i = 0; i < check.length; i++) {
                    if (has_checks.indexOf(check[i].id) >= 0)
                        continue;
                    if (check[i].id.length > 16) {
                        has_checks.push(check[i].id);
                        checks.push(check[i].id);
                    }
                }
                $.post("@Url.Action("AddFamilyMember")",
                    { 'ids': checks, 'family_id': family_id, "__RequestVerificationToken": token }, function (json) {
                        console.log(json);
                        layer.msg(json.message);
                    })
            }
            else {
                layer.msg("请选择要添加的成员", { icon: 0 });
            }
        });
        //检索
        $("#btn_search").click(function () {
            var keyword = $("#keyword").val();
            var where = {
                'keyword': keyword
            };
            params.url = "@Url.Action("GetList","Members")";
            params.where = where;
            getTable(params);
        })
    })


</script>
